﻿using IS_Ever_Green.DataAccess.Model.Repositories;
using IS_Ever_Green.DataAccess.Model;
using System.Windows.Input;

namespace IS_Ever_Green.ViewModel
{
    public class UserViewModel : BaseViewModel
    {
        private IUserRepository _userRepository;
        private UserModel _currentUser;
        private BaseViewModel _baseViewModel;

        public UserModel CurrentUser
        {
            get { return _currentUser; }
            set
            {
                _currentUser = value;
                OnPropertyChanged(nameof(CurrentUser));
            }
        }

        public BaseViewModel BaseViewModel
        {
            get { return _baseViewModel; }
            set { _baseViewModel = value; OnPropertyChanged(nameof(BaseViewModel)); }
        }


        public ICommand ShowHomeViewCommand { get; }
        public ICommand ShowReadyComputerViewCommand { get; }
        public ICommand ShowAccessoriesViewCommand { get; }
        public ICommand ShowLaptopViewCommand { get; }
        public ICommand ShowPhoneViewCommand { get; }
        public ICommand ShowProfileViewCommand { get; }

        public UserViewModel()
        {
            _userRepository = new UserRepository();
            ShowHomeViewCommand = new CommandViewModel(ExecuteShowHomeViewCommand);
            ShowReadyComputerViewCommand = new CommandViewModel(ExecuteShowReadyComputerViewCommand);
            ShowAccessoriesViewCommand = new CommandViewModel(ExecuteShowAccessoriesViewCommand);
            ShowLaptopViewCommand = new CommandViewModel(ExecuteShowLaptopViewCommand);
            ShowPhoneViewCommand = new CommandViewModel(ExecuteShowPnoneViewCommand);
            ShowProfileViewCommand = new CommandViewModel(ExecuteShowProfileViewCommand);

            ExecuteShowHomeViewCommand(null);
        }

        private void ExecuteShowHomeViewCommand(object obj)
        {
            BaseViewModel = new HomeUserViewModel();
        }

        private void ExecuteShowReadyComputerViewCommand(object obj)
        {
            BaseViewModel = new ReadyComputerViewModel();
        }

        private void ExecuteShowAccessoriesViewCommand(object obj)
        {
            BaseViewModel = new AccessoriesViewModel();
        }

        private void ExecuteShowLaptopViewCommand(object obj)
        {
            BaseViewModel = new LaptopViewModel();
        }

        private void ExecuteShowPnoneViewCommand(object obj)
        {
            BaseViewModel = new PhoneViewModel();
        }


        private void ExecuteShowProfileViewCommand(object obj)
        {
            BaseViewModel = new ProfileViewModel();
            (BaseViewModel as ProfileViewModel).CurrentUser = CurrentUser;
        }
    }
}
